package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;

/**
 * HP_WebService_Imp_AccountpassIsTrue
 * 宽带帐号密码验证
 * @author xuzhi
 *
 */
public class HP_WebService_Imp_AccountpassIsTrue implements WorkInterFace {

	@Override
	public String getName() {
		return "hp宽带帐号密码验证";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[2];
		in[0]=new Attr("Login", "值表示登录名全称：如hzhza12345678;对于普通宽带用户,不需要带后缀@zj(默认为@zj),但是对于卡用户,必须带后缀@tyt", AttrType.TYPE_String, true);
		in[1]=new Attr("Password","表示待验证的用户密码",AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[6];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("Result", "返回结果的根节点", AttrType.TYPE_String, true);
		out[2]=new Attr("error", "值表示错误信息, 比如请求报文数据格式不对", AttrType.TYPE_String, true);
		out[3]=new Attr("passed", "返回密码正确与否；返回结果：密码错误；密码正确", AttrType.TYPE_String, true);
		out[4]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[5]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("gethppass");
		attrsIn.setRequestMessage("<DN>"+(String) data.get("Login")+"</DN><password>"+(String) data.get("Password")+"</password>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", 0);
			map.put("Result", webService.getPattern("Result", returnXml));
			map.put("error", webService.getPattern("error", returnXml));
			String passResult="密码错误";
			int passed=Integer.parseInt(webService.getPattern("passed", returnXml));
			if(passed==1){
				passResult="密码正确";
			}
			map.put("passed", passResult);
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("Result", "");
			map.put("error", "");
			map.put("passed","" );
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
